#region "ThreadCultureManager"

/*
 * ####     Developer Name : Wang Yucai
 * 
 * ####     Development Tool : Microsoft VisualStudio 2010 Ultimate Edition
 * 
 * ####     Create Time : 2014/7/7 16:31:34
 * 
 * ####     Namespace : Masterduner.SourceStudio.Practices.DevelopmentLibrary.Globalization
 * 
 * ####     Type Name : ThreadCultureManager
 * 
 * ####     Full Name : Masterduner.SourceStudio.Practices.DevelopmentLibrary.Globalization.ThreadCultureManager
 * 
 * ####     Machine Name : GLCHQWYCWINW7
 * 
 * ####     UserName : GUOCOLAND/wangyucai
 * 
 * ####     CLR Version : 4.0.30319.1022
 * 
 * ####     Target Framework Version : 4.0
 */

#endregion

using System.Globalization;
using System.Threading;

namespace Masterduner.SourceStudio.Practices.DevelopmentLibrary.Globalization
{
    /// <summary>
    /// <para>Masterduner.SourceStudio.Practices.DevelopmentLibrary.Globalization.ThreadCultureManager</para>
    /// <para>
    /// 用于管理当前线程的<see cref="CultureInfo"/>信息。
    /// </para>
    /// </summary>
    /// <remarks>
    /// <para>Target Framework Version : 4.0</para>
    /// </remarks>
    public class ThreadCultureManager
    {
        private CultureInfo _currentCultureInfo;

        #region CurrentCultureInfo
        /// <summary>
        /// 设置或获取当前线程的<see cref="CultureInfo"/>信息。
        /// </summary>
        protected virtual CultureInfo CurrentCultureInfo
        {
            get { return _currentCultureInfo; }
            set { _currentCultureInfo = value; }
        }
        #endregion

        #region Constructor

        /// <summary>
        /// <para>构造函数：</para>
        /// <para>初始化一个<see cref="ThreadCultureManager" />对象实例。</para>
        /// </summary>
        /// <param name="cultureName"><see cref="CultureInfo"/>名称。</param>
        public ThreadCultureManager(string cultureName = "zh-CN")
        {
            this.CurrentCultureInfo = CultureExpando.CreateSpecialCulture(cultureName);
        }

        /// <summary>
        /// <para>构造函数：</para>
        /// <para>初始化一个<see cref="ThreadCultureManager" />对象实例。</para>
        /// </summary>
        /// <param name="lcid"><see cref="LocaleID"/>中的一个值。</param>
        public ThreadCultureManager(LocaleID lcid = LocaleID.ChinesePRC)
        {
            this.CurrentCultureInfo = CultureExpando.CreateSpecialCulture(lcid);
        }

        #endregion

        #region SetCultureInfo
        /// <summary>
        /// 设置当前线程的<see cref="CultureInfo"/>信息。
        /// </summary>
        public virtual void SetCultureInfo()
        {
            Thread.CurrentThread.CurrentCulture = this.CurrentCultureInfo;
        }
        #endregion

        #region SetUICultureInfo
        /// <summary>
        /// 设置当前线程UI的<see cref="CultureInfo"/>信息。
        /// </summary>
        public virtual void SetUICultureInfo()
        {
            Thread.CurrentThread.CurrentUICulture = this.CurrentCultureInfo;
        }
        #endregion

        #region SetThreadCultureInfo
        /// <summary>
        /// 设置当前线程和UI的<see cref="CultureInfo"/>信息。
        /// </summary>
        public virtual void SetThreadCultureInfo()
        {
            this.SetCultureInfo();
            this.SetUICultureInfo();
        }
        #endregion
    }
}

#region README

/*
 * ####     ©2014 Wang Yucai
 * 
 * ####     Contact me
 *                  
 *                  E-mail : Masterduner@Yeah.net
 *                  Mobile : 13621384677
 *                  QQ : 180261899
 */

#endregion